package org.datedemo;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.format.DateTimeFormatter;
import java.time.format.TextStyle;
import java.time.temporal.ChronoUnit;
import java.util.Locale;

public class LocalDate1 {
    public static void main(String[] args) {
        //现在系统日期
        LocalDate now = LocalDate.now();
        now = LocalDate.of(1985, 5, 5);
        now = LocalDate.parse("1985-10-05");
        now = LocalDate.parse("1985/03/05", DateTimeFormatter.ofPattern("yyyy/MM/dd"));
        now = LocalDate.parse("2000年10月25日", DateTimeFormatter.ofPattern("yyyy年MM月dd日"));


        //now = now.plusDays(-6);
        //now = now.minusDays(6);

        now = now.minus(800, ChronoUnit.YEARS);

        System.out.printf("%tF %<ta %<tA%n", now);


        System.out.println(now.getYear() + "年是：" + (now.isLeapYear() ? "闰年" : "平年"));



        now = LocalDate.now();
        DayOfWeek dayOfWeek = now.getDayOfWeek();
        System.out.println(dayOfWeek.getValue());
        System.out.println(dayOfWeek.getDisplayName(TextStyle.FULL, Locale.CHINA));
        System.out.println(dayOfWeek.getDisplayName(TextStyle.SHORT, Locale.CHINA));

        Month month = now.getMonth();
        System.out.println(month.getValue());
        System.out.println(month.getDisplayName(TextStyle.FULL, Locale.CHINA));
        System.out.println(month.getDisplayName(TextStyle.SHORT, Locale.CHINA));

        System.out.println(month.getDisplayName(TextStyle.FULL, Locale.TAIWAN));
        System.out.println(month.getDisplayName(TextStyle.SHORT, Locale.TAIWAN));


        var fmt = DateTimeFormatter.ofPattern("yyyy年MM月dd日 E M月 L月", Locale.CHINA);

        LocalDate d1 = LocalDate.now();
        System.out.println(fmt.format(d1));
        System.out.printf("%ta %<tA%n",d1);
        LocalDate d2 = LocalDate.of(1997, 7, 1);
        System.out.println(fmt.format(d2));
        System.out.printf("%ta %<tA%n",d2);
    }
}
